﻿using System;

namespace NEnsure.Rules
{
	public class EqualToRule<T> : BaseBusinessRule<T>, IBusinessRule<T> 
	{
		private readonly T _value; 

		public override string RuleKey
		{
			get { return "Equal-To Rule"; }
		}

		public EqualToRule(T value)
			: base("{value} must be equal to " + value)
		{
			_value = value;
		}

		public bool IsBrokenBy(T value)
		{
			if (object.Equals(value, null))
			{
				if (object.Equals(_value, null))
				{
					return true; 
				}

				return false; 
			}

			return !value.Equals(_value);
		}
	}
}
